<template>
  <div class="dashboard-editor-container">

    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="红包类型" prop="type">
        <el-select
          v-model="queryParams.type"
          placeholder="请选择"
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="option in typeOptions"
            :key="option.value"
            :label="option.label"
            :value="option.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="直播间id" prop="roomId">
        <el-input
          v-model="queryParams.roomId"
          placeholder="请输入直播间id"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="发红包uid" prop="uid">
        <el-input
          v-model="queryParams.uid"
          placeholder="请输入发红包用户uid"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="是否抢完" prop="isFinish">
        <el-select
          v-model="queryParams.isFinish"
          placeholder="红包是否被抢光"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="item in isFinishOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="红包时间">
        <el-date-picker
          v-model="queryParams.dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <panel-group @handleSetLineChart="handleSetLineChartData" :moneys=moneys />

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <line-chart :chart-data="lineChartData" />
    </el-row>
  </div>
</template>

<script>
import PanelGroup from './dashboard/PanelGroup'
import LineChart from './dashboard/LineChart'
import {recordView} from "@/api/activity/red/record";

const lineChartData = {
  sumList: {
    expectedData: [100],
    xAxis:["20210904"],
    names:['红包金额','已领红包金额','未抢红包金额']
  }
}

export default {
  name: 'RedPacketRecordChart',
  components: {
    PanelGroup,
    LineChart
  },
  created() {
    this.getInitView()
  },
  data() {
    return {
      lineChartData:lineChartData.sumList,
      queryParams: {
        xAxisNum: 30,
        dateRange: [],
        pageNum: 1,
        pageSize: 10,
        type:'',
        roomId:'',
        uid:'',
        isFinish:undefined,
        gainMoney:undefined,
        taxMinMoney:undefined,
        taxMoney:undefined,
        option:undefined
      },
      showSearch: true,
      typeOptions:[
        {
          value: 1,
          label: "随机红包"
        },
        {
          value: 2,
          label: "平均红包"
        },
        {
          value: 3,
          label: "系统红包"
        }
      ],
      isFinishOptions:[
        {
          value: 1,
          label: "是"
        },
        {
          value: 0,
          label: "否"
        }
      ],
      moneys:{
        total:0,
        gain:0,
        surplus:0,
        liveNum:0
      },
    }
  },
  methods: {
    /** 折线图 **/
    getInitView(){
      recordView(this.queryParams).then(response=>{
        if (response.data !== undefined){
          this.lineChartData = response.data
        }

        if (response.moneys !== undefined){
          this.moneys = response.moneys
        }
      })
    },
    /** 点击一个具体金额线路图标方法 **/
    handleSetLineChartData(type) {
      this.queryParams.option = type
      recordView(this.queryParams).then(response=>{
        if (response.data !== undefined){
          this.lineChartData = response.data
          if (type === 1){
            this.moneys.total = response.moneys.total
          } else if (type === 2){
            this.moneys.gain = response.moneys.total
          } else if (type === 3){
            this.moneys.surplus = response.moneys.total
          } else if (type === 4){
            this.moneys.liveNum = response.moneys.total
          }
        }
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.option = undefined
      this.addDateRange2(this.queryParams,this.queryParams.dateRange)
      recordView(this.queryParams).then(response=>{
        if (response.data !== undefined){
          this.lineChartData = response.data
        }

        if (response.moneys !== undefined){
          this.moneys = response.moneys
        }
      })
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
          xAxisNum: 30,
          dateRange: [],
          pageNum: 1,
          pageSize: 10,
          type:'',
          roomId:'',
          uid:'',
          isFinish:undefined,
          gainMoney:undefined,
          taxMinMoney:undefined,
          taxMoney:undefined,
          option:undefined
      }
      this.getInitView();
    },
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
